<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="domain.entities.interfaces.*"%>
<%@ page import="domain.dao.interfaces.*"%>
<%@ page import="java.util.List"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Show details</title>
<link rel="stylesheet" type="text/css" href="/mdoc-project/css/bootstrap_Boris.css">
<base href="<%=request.getScheme()%>://<%=request.getServerName()%>:<%=request.getServerPort()%><%=request.getContextPath()%>/">
</head>
<body>


	<%
		boolean connected = session
				.getAttribute(DomainUtils.CURRENT_USER_STRING) != null;

		ApplicationContext context = util.SpringUtils
				.getApplicationContext();
		IDAOContact daoContact = (IDAOContact) context
				.getBean("beanDAOContact");

		String strIdContact = request.getParameter("selected_contact");
		int idContact = Integer.parseInt(strIdContact);
		IContact c = daoContact.getById(idContact);

		if (connected == false) {
			request.setAttribute(DomainUtils.ALERT_ERROR_STRING,
					"You must be connected");
		}
		else if (c == null) {
			request.setAttribute(DomainUtils.ALERT_ERROR_STRING,
					"This contact has been deleted.");
		}
	%>

	<%@include file="/pages/common_style/header.jsp"%>
	<%@include file="/pages/common_style/alerts.jsp"%>

	<div class="panel panel-default">
		<div class="panel-heading"></div>

		<table class="table">
			<thead>
				<tr>
					<th>Information</th>
					<th>Value</th>
				</tr>
			</thead>
			<tbody>
				<%
					if (connected && c != null) {
				%>
				<tr>
					<td>First name</td>
					<td><%=c.getFirstName()%></td>
				</tr>
				<tr>
					<td>Last name</td>
					<td><%=c.getLastName()%></td>
				</tr>
				<tr>
					<td>E-mail</td>
					<td><%=c.getEmail()%></td>
				</tr>
				<tr>
					<td>Street</td>
					<td><%=c.getAdd().getStreet()%></td>
				</tr>
				<tr>
					<td>City</td>
					<td><%=c.getAdd().getCity()%></td>
				</tr>
				<tr>
					<td>Zip</td>
					<td><%=c.getAdd().getZip()%></td>
				</tr>
				<tr>
					<td>Country</td>
					<td><%=c.getAdd().getCountry()%></td>
				</tr>
				<%
					if (c instanceof IEntreprise) {
				%>
				<tr>
					<td>Siret number</td>
					<td><%=((IEntreprise) c).getNumSiret()%></td>
				</tr>
				<%
					}
						for (IPhoneNumber p : c.getPhones()) {
				%>
				<tr>
					<td><%=p.getPhoneKind()%></td>
					<td><%=p.getPhoneNumber()%></td>
				</tr>
				<%
					}
				%>
				<tr>
					<td>Member of following contact groups</td>
					<td>
						<div class="form-control" style="overflow: scroll; height: 150px;">
							<ul>
								<%
									for (IContactGroup cg : c.getBooks()) {
								%>
								<li><%=cg.getGroupName()%></li>
								<%
									}
								%>
							</ul>
						</div>
					</td>
				</tr>
				<%
					}
				%>
			</tbody>
		</table>
	</div>

	<%
		if(connected) {
	%>
	
	<br>
	<a class="btn btn-default navbar-btn" href="pages/showAllContact.jsp">Return</a>
	<%
		}
	%>


	<%@include file="/pages/common_style/footer.jsp"%>
</body>
</html>